home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / hpgl2ps.zip / HPGL2PS.C < prev    next >
C/C++ Source or Header  |  1989-08-08  |  3KB  |  127 lines

  1. /* hpgl2ps.c */
  2. #include "ext.h"
  3.  
  4. #define USAGE "Usage: hpgl2ps [-43BAmr] [-l line sizes] [-s scale] [-x offset] [-y offset] [-w font_width] [-h font_height] [file]\n"
  5.  
  6. main(argc, argv)
  7. /*
  8.  *  hpgl2ps.c
  9.  *
  10.  *  Modified by J.R. Nickerson, G.W. Kokodyniak
  11.  *  University of Toronto, Department of Mechanical Enginnering
  12.  *
  13.  *  Further modified by Gordon Jacobs, University of Calif, Berkeley
  14.  *   Added Scaling,Ticks,modified userdefchar(),sizes for 8.5x11 paper
  15.  *
  16.  */
  17. int     argc;
  18. char   *argv[];
  19. {
  20.     extern int optind;
  21.     extern char *optarg;
  22.  
  23.     int     ch;                                 /* GWKMOD */
  24.     int     op;                                 /* GWKMOD */
  25.     /* GWK: char    op; */
  26.     int        MANUAL_FEED = 0;            /* DEFAULT: No manual feed */
  27.  
  28.     PaperSize = "A";
  29.     Mode = "HPGL";
  30.     plotcoords();
  31.  
  32.     plotinit();            /* Get other initialiasations */
  33.  
  34.     while ((ch = getopt(argc, argv, "AB43l:ms:x:y:rh:w:")) != EOF)
  35.     {
  36.     switch (ch)
  37.     {
  38.     case '4':        /* HP-GL ISO A4 297mm * 210mm */
  39.         PaperSize = "A4";
  40.         plotcoords();
  41.         break;
  42.  
  43.     case '3':        /* HP-GL ISO A3 420mm * 297mm */
  44.         PaperSize = "A3";
  45.         plotcoords();
  46.         break;
  47.  
  48.     case 'A':        /* HP-GL ANSI A 11 * 8.5inch */
  49.         PaperSize = "A";
  50.         plotcoords();
  51.         break;
  52.  
  53.     case 'B':        /* HP-GL ANSI B 17 * 11inch */
  54.         PaperSize = "B";
  55.         plotcoords();
  56.         break;
  57.  
  58.     case 'l':        /* change line size option */
  59.         changesizes(optarg);
  60.         break;
  61.  
  62.     case 'm':        /* enable manual feed on Laserwriter */
  63.         MANUAL_FEED = 1;
  64.         break;
  65.  
  66.     case 'r':        /* rotate the plot 90 degrees */
  67.         LANDSCAPE = 0;
  68.         break;
  69.  
  70.     case 's':        /* scale the plot from 0.1 to 3.0 times */
  71.         SCALE = atof(optarg);
  72.         if (SCALE < 0.1)
  73.         SCALE = 0.1;
  74.         else
  75.         if (SCALE > 3)
  76.         SCALE = 3;
  77.         break;
  78.  
  79.     case 'h':
  80.         FONT_H_MULT = atof(optarg);
  81.         break;
  82.  
  83.     case 'w':
  84.         FONT_W_MULT = atof(optarg);
  85.         break;
  86.  
  87.     case 'x':        /* place an X offset (in mm) */
  88.         xoffset = atof(optarg);
  89.         break;
  90.  
  91.     case 'y':        /* place an Y offset (in mm) */
  92.         yoffset = atof(optarg);
  93.         break;
  94.  
  95.     default:
  96.         fprintf(stderr, "%s\n", USAGE);
  97.         exit(1);
  98.     }
  99.     }
  100.     if (optind == argc)
  101.     stream = stdin;
  102.     else if ((stream = fopen(argv[optind], "r")) == NULL)
  103.     {
  104.     fprintf(stderr, "ERROR: cannot open \"%s\"\n", argv[optind]);
  105.     exit(1);
  106.     }
  107.     ps_macros();            /* Output PostScript Macros */
  108.  
  109.     viewport();                /* Scale the viewport for the plot */
  110.  
  111.     printf("/%s %g Font\n", font, char_height);
  112.  
  113.     if (MANUAL_FEED)
  114.     manualfeed(1);
  115.  
  116.     while ((op = getc(stream)) != EOF)
  117.     if (isalpha(op) > 0)
  118.         hpglcom(op);
  119.  
  120.     end_draw();
  121.  
  122.     printf("showpage\n");
  123.  
  124.     if (MANUAL_FEED)
  125.     manualfeed(0);
  126. }
  127.